package com.aaa.ssm.controller;

import com.aaa.ssm.entity.Scenic;
import com.aaa.ssm.entity.TScenicPic;
import com.aaa.ssm.service.CommonFileHandlerService;
import com.aaa.ssm.service.ScenicService;
import com.aaa.ssm.service.TScenicPicService;
import com.aaa.ssm.util.Page;
import com.aaa.ssm.util.Result;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;


@RequestMapping("pic")
@RestController
public class TScenicPicController extends BaseController {
    @Resource
    private TScenicPicService tScenicPicService;
    @Resource
    private CommonFileHandlerService commonFileHandlerService;
    @PostMapping("queryPage")
    public Result queryPage(@RequestBody Page<TScenicPic> page) {
        return success(tScenicPicService.queryAll(page));
    }
    /**
     * 文件上传对象  必须使用@RequestParam绑定上传对象,不可以少，少了上传不了
     * MultipartFile
     * @param file1
     * @return
     */
    @PostMapping("uploadFile")
    public Result uploadFile(@RequestParam MultipartFile file1){
        //调用封装的服务接口
        return success(commonFileHandlerService.uploadFile(file1,"scenic/pic1/"));
    }

    /**
     * 新加部门
     * @param scenic 实体
     * @return 返回
     */
    @PostMapping("add")
    public Result add(@RequestBody TScenicPic scenic){
        return success(tScenicPicService.add(scenic));
    }

    /**
     * 更新部门
     * @param scenic 实体
     * @return 返回
     */
    @PostMapping("update")
    public Result update(@RequestBody TScenicPic scenic){
        return success(tScenicPicService.update(scenic));
    }

    /**
     * 删除部门
     * @param id 主键
     * @return 返回
     */
    @DeleteMapping("delete/{id}")
    public Result delete(@PathVariable("id") Integer id){
        return success(tScenicPicService.delete(id));
    }
}
